<div class="content-wrapper">
	<section class="content-header">
		<h1>
			用户列表			
			<if condition="$user_group_id gt 0">
       			<small>【{$userGroupInfo.name}】</small>
       		</if>        		
		</h1>
		<ol class="breadcrumb">
			<li><a href="/admin"><i class="fa fa-dashboard"></i> 首页</a></li>
			<li class="active">账号管理</li>
			<li class="active">用户列表</li>
		</ol>
	</section>
	<section class="content">
		<div class="box">
			<div class="box-header with-border">
				<form class="form-inline" action="/admin/user/userList" method="get">
					<if condition="$user_group_id eq 0">
						<div class="form-group">
							<label for="username">用户名 </label> 
							<input type="text" class="form-control" id="username" name="username" placeholder="用户名" value="{$username}">
						</div>
						<div class="form-group">
							<label for="name">姓名 </label> 
							<input type="text" class="form-control" id="name" name="name" placeholder="姓名" value="{$name}">
						</div>
						<div class="form-group">
							<label for="department_id">部门 </label> 
							<select class="form-control" name="department_id" id="department_id">
                       			<option value="-1">选择部门</option>
                       			<foreach name="departmentList" item="department">
                       				<option value="{$department.id}" <if condition="$department['id'] eq $department_id">selected</if>>{$department.name}</option>
                       			</foreach>                            			
                       		</select>
						</div>
						<button type="submit" class="btn btn-info" id="save-btn">查询</button>&nbsp;
						<button type="button" class="btn btn-danger" onclick="window.location.href='/admin/user/editUserInfo';">添加</button>
					</if>															
				</form>
			</div>
			<div class="box-body">
				<table class="table table-bordered">
					<tbody>
						<tr>
							<th style="width: 40px">ID</th>
							<th>用户名</th>
							<th>姓名</th>
							<th>昵称</th>
							<th>性别</th>
							<th>部门</th>
							<th>状态</th>
							<th style="width: 320px">操作</th>
						</tr>
						<foreach name="userDepartmentList" item="userDepartment">
                         	<tr>
                         		<td colspan="9"><label style="width:250px;font-weight: bold;" class="position-relative">{$userDepartment.departmentInfo.name}</label></td>
                         	</tr>
                         	<foreach name="userDepartment.userList" item="user">
                         		<tr>
                         			<td>{$user.id}</td>
                         			<td>{$user.username}</td>
                         			<td>{$user.name}</td>
                         			<td>{$user.nickname}</td>
                         			<td><if condition="$user.sex eq 1">男<else/>女</if></td>
                         			<td><php>echo $departmentList[$user['department_id']]['name'];</php></td>
                         			<td><if condition="$user.status eq 1">正常<else/><span style="color:red;">已关闭</span></if></td>
                         			<td>
                         				<button class="btn btn-info btn-xs" type="button" onclick="window.location.href='/admin/user/userFunctionList?user_id={$user.id}'">查看权限</button>&nbsp;
                         				<button class="btn btn-success btn-xs" type="button" onclick="window.location.href='/admin/user/setUserFunction?user_id={$user.id}'">设置权限</button>&nbsp;
	                          			<button class="btn btn-primary btn-xs" type="button" onclick="window.location.href='/admin/user/setUserExtFunction?user_id={$user.id}'">扩展设置</button>&nbsp;
	                          			<button class="btn btn-warning btn-xs" type="button" onclick="window.location.href='/admin/user/editUserInfo?id={$user.id}'">修改</button>&nbsp;	                          				                          		
	                          			<if condition="$user.status eq 1">
	                          				<button class="btn btn-danger btn-xs close-btn" type="button" data-id="{$user.id}" data-status="-1">关闭账号</button>&nbsp;	                          				
	                          			<else/>
	                          				<button class="btn btn-danger btn-xs close-btn" type="button" data-id="{$user.id}" data-status="1">开启账号</button>&nbsp;	                          				
	                          			</if>
                         			</td>
                         		</tr>
                         	</foreach>
                         </foreach>
					</tbody>
				</table>
			</div>			
		</div>
	</section>
</div>

<script type="text/javascript">
$(function(){
	//关闭/开启账号
	$(".close-btn").click(function(){
		var user_id = $(this).attr('data-id');
		var status = $(this).attr('data-status');
		
		var msg = '确定要关闭该账号吗？';
		if(status == 1) {
			msg = '确定要开启该账号吗？';
		}
		
		ArtDialogHlp.showConfirm('提示', msg, function(){
			$.post("/admin/user/deleteUser", {user_id:user_id, status:status}, function(_data) {
            	if(_data.Code == 999) {
            		ArtDialogHlp.showInfo('提示', '操作成功', function(){
    					window.location.href = '/admin/user/userList';
    				});
    			} else {
    				ArtDialogHlp.showInfo('提示', _data.Msg);
    			}
            },'json');
		});			
	});
});
</script>